package fr.univ.lille1.android;

import android.text.Html;
import android.widget.Button;
import android.widget.TextView;

import com.googlecode.androidannotations.annotations.AfterViews;
import com.googlecode.androidannotations.annotations.Click;
import com.googlecode.androidannotations.annotations.EActivity;
import com.googlecode.androidannotations.annotations.ViewById;
import com.googlecode.androidannotations.annotations.res.HtmlRes;
import com.googlecode.androidannotations.annotations.res.StringRes;

import fr.univ.lille1.android.auth.AuthenticationService;

@EActivity(R.layout.activity_connect)
public class AuthenticationActivity extends BaseActivity {
	// Gui.
	@ViewById(R.id.textViewWelcome)
	TextView mTextViewWelcome;
	@ViewById(R.id.buttonTagThisSignIn)
	Button mButtonTagThisSignIn;

	// Resources.
	@HtmlRes(R.string.text_welcome)
	CharSequence mTextWelcome;
	@StringRes(R.string.app_name)
	String mAppName;

	@Override
	public void onSignedIn(AuthenticationService service) {
		super.onSignedIn(service);
		CommentActivity_.intent(this).start();
		finish();
	}

	@Override
	public void onSignInFailed() {
		super.onSignInFailed();
		SignInActivity_.intent(this).start();
		finish();
	}

	@AfterViews
	void afterView() {
		final String textWelcome = String.format(mTextWelcome.toString(),
				mAppName);
		mTextViewWelcome.setText(Html.fromHtml(textWelcome));
	}

	@Click(R.id.buttonTagThisSignIn)
	void tagThisSignInClick() {
		mAuthentication.connect();
	}
}
